package com.fuze.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuze.domain.dto.ContractQueryDTO;
import com.fuze.domain.dto.DataGridView;
import com.fuze.domain.dto.MinimumGuaranteeContractDTO;
import com.fuze.domain.model.MinimumGuaranteeContract;
import com.fuze.mapper.MinimumGuaranteeContractMapper;
import com.fuze.service.MinimumGuaranteeContractService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.validation.constraints.Min;
import java.util.Arrays;
import java.util.List;

/**
 * @author sepc_
 * @date 5/19/2021 15:02
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class MinimumGuaranteeContractServiceImpl implements MinimumGuaranteeContractService {

    final MinimumGuaranteeContractMapper minimumGuaranteeContractMapper;

    @Override
    public DataGridView queryByType(ContractQueryDTO queryDTO) {
        Page<MinimumGuaranteeContract> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());
        this.minimumGuaranteeContractMapper.selectPage(page, null);
        return new DataGridView(page.getTotal(), page.getRecords());
    }

    @Override
    public MinimumGuaranteeContract findById(Integer id) {
        return this.minimumGuaranteeContractMapper.selectById(id);
    }

    @Override
    public int add(MinimumGuaranteeContractDTO minimumGuaranteeContractDTO) {
        MinimumGuaranteeContract contract = new MinimumGuaranteeContract();
        BeanUtils.copyProperties(minimumGuaranteeContractDTO, contract);
        return this.minimumGuaranteeContractMapper.insert(contract);

    }

    @Override
    public int update(MinimumGuaranteeContractDTO minimumGuaranteeContractDTO) {
        MinimumGuaranteeContract contract = new MinimumGuaranteeContract();
        BeanUtils.copyProperties(minimumGuaranteeContractDTO, contract);
        return this.minimumGuaranteeContractMapper.updateById(contract);
    }

    @Override
    public int delete(Integer[] ids) {
        List<Integer> asList = Arrays.asList(ids);
        return this.minimumGuaranteeContractMapper.deleteBatchIds(asList);
    }
}
